package com.sailfish.springbootdemo.dao.db1;

import com.sailfish.springbootdemo.common.DB1TableName;
import com.sailfish.springbootdemo.pojo.db1.PcbaCompany;
import com.sailfish.springbootdemo.pojo.db1.PcbaLine;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.Date;
import java.util.List;

public interface PcbaLineDao {

    /**
     * 查询所有
     *
     * @return
     */
    @Results(id = "pcbaLineResultMap", value = {
            @Result(column = "pcba_line_id", property = "pcbaLineId", jdbcType = JdbcType.INTEGER),
            @Result(column = "pcba_line_name_cn", property = "pcbaLineNameCn", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pcba_line_name_en", property = "pcbaLineNameEn", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pcba_company_id", property = "pcbaCompanyId", jdbcType = JdbcType.INTEGER),
            @Result(column = "pcba_workshop_id", property = "pcbaWorkshopId", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "sort", property = "sort", jdbcType = JdbcType.INTEGER),
            @Result(column = "pcba_line_type", property = "pcbaLineType", jdbcType = JdbcType.INTEGER),
            @Result(column = "pcba_line_level", property = "pcbaLineLevel", jdbcType = JdbcType.INTEGER),
            @Result(column = "pcba_line_level_audit", property = "pcbaLineLevelAudit", jdbcType = JdbcType.INTEGER),
            @Result(column = "pcba_process_id", property = "pcbaProcessId", jdbcType = JdbcType.INTEGER),
            @Result(column = "notes", property = "notes", jdbcType = JdbcType.VARCHAR),
            @Result(column = "notes_audit", property = "notesAudit", jdbcType = JdbcType.VARCHAR),
            @Result(column = "is_filled_declare", property = "isFilledDeclare", jdbcType = JdbcType.INTEGER),
            @Result(column = "is_filled_actual", property = "isFilledActual", jdbcType = JdbcType.INTEGER),
            @Result(column = "begin_time_declare", property = "beginTimeDeclare", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "end_time_declare", property = "endTimeDeclare", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "params_status_declare", property = "paramsStatusDeclare", jdbcType = JdbcType.INTEGER),
            @Result(column = "params_notes_declare", property = "paramsNotesDeclare", jdbcType = JdbcType.VARCHAR),
            @Result(column = "begin_time_actual", property = "beginTimeActual", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "end_time_actual", property = "endTimeActual", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "params_status_actual", property = "paramsStatusActual", jdbcType = JdbcType.INTEGER),
            @Result(column = "params_notes_actual", property = "paramsNotesActual", jdbcType = JdbcType.VARCHAR),
            @Result(column = "submitter", property = "submitter", jdbcType = JdbcType.INTEGER),
            @Result(column = "auditors", property = "auditors", jdbcType = JdbcType.VARCHAR),
            @Result(column = "params_status_base", property = "paramsStatusBase", jdbcType = JdbcType.INTEGER),
            @Result(column = "params_remark_base", property = "paramsRemarkBase", jdbcType = JdbcType.VARCHAR),
            @Result(column = "lock_declare", property = "lockDeclare", jdbcType = JdbcType.INTEGER),
            @Result(column = "final_status", property = "finalStatus", jdbcType = JdbcType.INTEGER),
            @Result(column = "is_first_create", property = "isFirstCreate", jdbcType = JdbcType.INTEGER),
    })
    @Select("<script>" +
            "select * from " + DB1TableName.PCBA_LINE + " where 1 = 1 " +
            /*"<if test='searchPcbaLineName != null and searchPcbaLineName != \"\" '>" +
            " and (pcba_line_name_cn like CONCAT('%',#{searchPcbaLineName},'%') or pcba_line_name_en like CONCAT('%',#{searchPcbaLineName},'%'))" +
            "</if>" +*/
            "<if test='searchPcbaLineName != null and searchPcbaLineName != \"\" '>" +
            " and (pcba_line_name_cn = #{searchPcbaLineName} or pcba_line_name_en = #{searchPcbaLineName})" +
            "</if>" +
            "<if test='pcbaCompanyId != null and pcbaCompanyId != \"\" '>" +
            " and pcba_company_id = #{pcbaCompanyId}" +
            "</if>" +
            "<if test='pcbaProcessId != null and pcbaProcessId != \"\" '>" +
            " and pcba_process_id = #{pcbaProcessId}" +
            "</if>" +
            "<if test='pcbaWorkshopId != null and pcbaWorkshopId != \"\" '>" +
            " and pcba_workshop_id = #{pcbaWorkshopId}" +
            "</if>" +
            "<if test='status != null and status != \"\" '>" +
            " and status = #{status}" +
            "</if>" +
            "<if test='paramsStatusDeclare != null and paramsStatusDeclare != \"\" '>" +
            " and params_status_declare = #{paramsStatusDeclare}" +
            "</if>" +
            "<if test='paramsStatusActual != null and paramsStatusActual != \"\" '>" +
            " and params_status_actual = #{paramsStatusActual}" +
            "</if>" +
            "<if test='paramsStatusBase != null and paramsStatusBase != \"\" '>" +
            " and params_status_base = #{paramsStatusBase}" +
            "</if>" +
            "<if test=\"companyIdList != null and companyIdList.size() > 0 \">\n" +
            "                and pcba_company_id in\n" +
            "                <foreach item=\"item\" index=\"index\" collection=\"companyIdList\"\n" +
            "                         open=\"(\" separator=\",\" close=\")\">\n" +
            "                    #{item}\n" +
            "                </foreach>\n" +
            "            </if>\n" +
            " order by create_time desc" +
            "<if test='begin != null and pageSize != null and pageSize != \"\" '>" +
            " limit #{begin}, #{pageSize}" +
            "</if>" +
            "</script>")
    List<PcbaLine> getAllPcbaLine(@Param("searchPcbaLineName") String searchPcbaLineName, @Param("pcbaCompanyId") Integer pcbaCompanyId, @Param("pcbaWorkshopId") Integer pcbaWorkshopId, @Param("pcbaProcessId") Integer pcbaProcessId, @Param("status") Integer status, @Param("paramsStatusDeclare") Integer paramsStatusDeclare, @Param("paramsStatusActual") Integer paramsStatusActual, @Param("paramsStatusBase") Integer paramsStatusBase, @Param("begin") Integer begin, @Param("pageSize") Integer pageSize, @Param("companyIdList") List<Integer> companyIdList);

    /**
     * 查询所有
     *
     * @return
     */
    @ResultMap(value = "pcbaLineResultMap")
    @Select("<script>" +
            "select * from " + DB1TableName.PCBA_LINE + " where 1 = 1 " +
            /*"<if test='searchPcbaLineName != null and searchPcbaLineName != \"\" '>" +
            " and (pcba_line_name_cn like CONCAT('%',#{searchPcbaLineName},'%') or pcba_line_name_en like CONCAT('%',#{searchPcbaLineName},'%'))" +
            "</if>" +*/
            "<if test='searchPcbaLineName != null and searchPcbaLineName != \"\" '>" +
            " and (pcba_line_name_cn = #{searchPcbaLineName} or pcba_line_name_en = #{searchPcbaLineName})" +
            "</if>" +
            "<if test='pcbaCompanyId != null and pcbaCompanyId != \"\" '>" +
            " and pcba_company_id = #{pcbaCompanyId}" +
            "</if>" +
            "<if test='pcbaProcessId != null and pcbaProcessId != \"\" '>" +
            " and pcba_process_id = #{pcbaProcessId}" +
            "</if>" +
            "<if test='pcbaWorkshopId != null and pcbaWorkshopId != \"\" '>" +
            " and pcba_workshop_id = #{pcbaWorkshopId}" +
            "</if>" +
            "<if test='status != null and status != \"\" '>" +
            " and status = #{status}" +
            "</if>" +
            "<if test='paramsStatusDeclare != null and paramsStatusDeclare != \"\" '>" +
            " and params_status_declare = #{paramsStatusDeclare}" +
            "</if>" +
            "<if test='paramsStatusActual != null and paramsStatusActual != \"\" '>" +
            " and params_status_actual = #{paramsStatusActual}" +
            "</if>" +
            "<if test='paramsStatusBase != null and paramsStatusBase != \"\" '>" +
            " and params_status_base = #{paramsStatusBase}" +
            "</if>" +
            "<if test='lockDeclare != null and lockDeclare != \"\" '>" +
            " and lock_declare = #{lockDeclare}" +
            "</if>" +
            "<if test='lockDeclare != null and lockDeclare != \"\" '>" +
            " and lock_declare = #{lockDeclare}" +
            "</if>" +
            "<if test=\"companyIdList != null and companyIdList.size() > 0 \">\n" +
            "                and pcba_company_id in\n" +
            "                <foreach item=\"item\" index=\"index\" collection=\"companyIdList\"\n" +
            "                         open=\"(\" separator=\",\" close=\")\">\n" +
            "                    #{item}\n" +
            "                </foreach>\n" +
            "            </if>\n" +
            " order by SUBSTRING_INDEX(pcba_line_name_cn, ' ', 1),CAST(SUBSTRING_INDEX(pcba_line_name_cn, ' ', -1) AS SIGNED)" +
            "</script>")
    List<PcbaLine> getAllPcbaLineForPcba(@Param("searchPcbaLineName") String searchPcbaLineName, @Param("pcbaCompanyId") Integer pcbaCompanyId, @Param("pcbaWorkshopId") Integer pcbaWorkshopId, @Param("pcbaProcessId") Integer pcbaProcessId, @Param("status") Integer status, @Param("paramsStatusDeclare") Integer paramsStatusDeclare, @Param("paramsStatusBase") Integer paramsStatusBase, @Param("paramsStatusActual") Integer paramsStatusActual, @Param("lockDeclare") Integer lockDeclare, @Param("companyIdList") List<Integer> companyIdList);

    /**
     * 查询最终的通过的线体
     */
    @ResultMap(value = "pcbaLineResultMap")
    @Select("<script>" +
            "select * from " + DB1TableName.PCBA_LINE + " where 1 = 1 " +
            "<if test='searchPcbaLineName != null and searchPcbaLineName != \"\" '>" +
            " and (pcba_line_name_cn = #{searchPcbaLineName} or pcba_line_name_en = #{searchPcbaLineName})" +
            "</if>" +
            "<if test='pcbaCompanyId != null and pcbaCompanyId != \"\" '>" +
            " and pcba_company_id = #{pcbaCompanyId}" +
            "</if>" +
            "<if test='pcbaProcessId != null and pcbaProcessId != \"\" '>" +
            " and pcba_process_id = #{pcbaProcessId}" +
            "</if>" +
            "<if test='pcbaWorkshopId != null and pcbaWorkshopId != \"\" '>" +
            " and pcba_workshop_id = #{pcbaWorkshopId}" +
            "</if>" +
            "<if test='finalStatus != null and finalStatus != \"\" '>" +
            " and final_status = #{finalStatus}" +
            "</if>" +
            "<if test=\"companyIdList != null and companyIdList.size() > 0 \">\n" +
            "                and pcba_company_id in\n" +
            "                <foreach item=\"item\" index=\"index\" collection=\"companyIdList\"\n" +
            "                         open=\"(\" separator=\",\" close=\")\">\n" +
            "                    #{item}\n" +
            "                </foreach>\n" +
            "            </if>\n" +
            " order by create_time desc" +
            "</script>")
    List<PcbaLine> getAllOkLine(@Param("searchPcbaLineName") String searchPcbaLineName, @Param("pcbaCompanyId") Integer pcbaCompanyId, @Param("pcbaWorkshopId") Integer pcbaWorkshopId, @Param("pcbaProcessId") Integer pcbaProcessId, @Param("finalStatus") Integer finalStatus, @Param("companyIdList") List<Integer> companyIdList);

    /**
     * 根据工厂+车间查询smt线体
     *
     * @param pcbaCompanyId
     * @param pcbaWorkshopId
     * @return
     */
    @ResultMap(value = "pcbaLineResultMap")
    @Select("select * from " + DB1TableName.PCBA_LINE + " where pcba_company_id = #{pcbaCompanyId} and pcba_workshop_id = #{pcbaWorkshopId} and pcba_line_type = 1")
    List<PcbaLine> getAllSmtLineByCompanyAndWorkshop(@Param("pcbaCompanyId") Integer pcbaCompanyId, @Param("pcbaWorkshopId") Integer pcbaWorkshopId);

    /**
     * 查询所有 有设备需要审核工艺实际能力的 线体
     *
     * @param searchPcbaLineName
     * @param pcbaCompanyId
     * @param pcbaWorkshopId
     * @param pcbaProcessId
     * @param status
     * @return
     */
    @Select("<script>" +
            "select * from " + DB1TableName.PCBA_LINE + " where 1 = 1 " +
            "<if test='searchPcbaLineName != null and searchPcbaLineName != \"\" '>" +
            " and (pcba_line_name_cn = #{searchPcbaLineName} or pcba_line_name_en = #{searchPcbaLineName})" +
            "</if>" +
            "<if test='pcbaCompanyId != null and pcbaCompanyId != \"\" '>" +
            " and pcba_company_id = #{pcbaCompanyId}" +
            "</if>" +
            "<if test='pcbaProcessId != null and pcbaProcessId != \"\" '>" +
            " and pcba_process_id = #{pcbaProcessId}" +
            "</if>" +
            "<if test='pcbaWorkshopId != null and pcbaWorkshopId != \"\" '>" +
            " and pcba_workshop_id = #{pcbaWorkshopId}" +
            "</if>" +
            "<if test='status != null and status != \"\" '>" +
            " and status = #{status}" +
            "</if>" +
            " order by create_time desc" +
            "</script>")
    @ResultMap(value = "pcbaLineResultMap")
    List<PcbaLine> getAllPcbaLineWithAuditDevice(@Param("searchPcbaLineName") String searchPcbaLineName, @Param("pcbaCompanyId") Integer pcbaCompanyId, @Param("pcbaWorkshopId") Integer pcbaWorkshopId, @Param("pcbaProcessId") Integer pcbaProcessId, @Param("status") Integer status);

    /**
     * 根据复选条件查询
     *
     * @param status
     * @param begin
     * @param pageSize
     * @return
     */
    @Select("<script>" +
            "select * from " + DB1TableName.PCBA_LINE + " where 1 = 1 " +
            "<if test=\"pcbaLineNameList != null and pcbaLineNameList.size() > 0 \">\n" +
            "                and pcba_line_name_cn in\n" +
            "                <foreach item=\"item\" index=\"index\" collection=\"pcbaLineNameList\"\n" +
            "                         open=\"(\" separator=\",\" close=\")\">\n" +
            "                    #{item}\n" +
            "                </foreach>\n" +
            "            </if>\n" +
            "<if test=\"pcbaWorkshopIdList != null and pcbaWorkshopIdList.size() > 0 \">\n" +
            "                and pcba_workshop_id in\n" +
            "                <foreach item=\"item\" index=\"index\" collection=\"pcbaWorkshopIdList\"\n" +
            "                         open=\"(\" separator=\",\" close=\")\">\n" +
            "                    #{item}\n" +
            "                </foreach>\n" +
            "            </if>\n" +
            "<if test=\"pcbaProcessIdList != null and pcbaProcessIdList.size() > 0 \">\n" +
            "                and pcba_process_id in\n" +
            "                <foreach item=\"item\" index=\"index\" collection=\"pcbaProcessIdList\"\n" +
            "                         open=\"(\" separator=\",\" close=\")\">\n" +
            "                    #{item}\n" +
            "                </foreach>\n" +
            "            </if>\n" +
            "<if test='status != null and status != \"\" '>" +
            " and status = #{status}" +
            "</if>" +
            "<if test='paramsStatusBase != null and paramsStatusBase != \"\" '>" +
            " and params_status_base = #{paramsStatusBase}" +
            "</if>" +
            "<if test=\"companyIdList != null and companyIdList.size() > 0 \">\n" +
            "                and pcba_company_id in\n" +
            "                <foreach item=\"item\" index=\"index\" collection=\"companyIdList\"\n" +
            "                         open=\"(\" separator=\",\" close=\")\">\n" +
            "                    #{item}\n" +
            "                </foreach>\n" +
            "            </if>\n" +
            " order by pcba_company_id,pcba_workshop_id, SUBSTRING_INDEX(pcba_line_name_cn, ' ', 1),CAST(SUBSTRING_INDEX(pcba_line_name_cn, ' ', -1) AS SIGNED)" +
            "<if test='begin != null and pageSize != null and pageSize != \"\" '>" +
            " limit #{begin}, #{pageSize}" +
            "</if>" +
            "</script>")
    @ResultMap(value = "pcbaLineResultMap")
    List<PcbaLine> getAllPcbaLineView(@Param("pcbaLineNameList") List<String> pcbaLineNameList, @Param("pcbaWorkshopIdList") List<String> pcbaWorkshopIdList, @Param("pcbaProcessIdList") List<String> pcbaProcessIdList, @Param("status") Integer status, @Param("paramsStatusBase") Integer paramsStatusBase, @Param("begin") Integer begin, @Param("pageSize") Integer pageSize, @Param("companyIdList") List<Integer> companyIdList);

    /**
     * 查询总数
     */
    @Select("<script>" +
            "select count(*) from " + DB1TableName.PCBA_LINE + " where 1 = 1 " +
            "<if test=\"pcbaLineNameList != null and pcbaLineNameList.size() > 0 \">\n" +
            "                and pcba_line_name_cn in\n" +
            "                <foreach item=\"item\" index=\"index\" collection=\"pcbaLineNameList\"\n" +
            "                         open=\"(\" separator=\",\" close=\")\">\n" +
            "                    #{item}\n" +
            "                </foreach>\n" +
            "            </if>\n" +
            "<if test=\"pcbaWorkshopIdList != null and pcbaWorkshopIdList.size() > 0 \">\n" +
            "                and pcba_workshop_id in\n" +
            "                <foreach item=\"item\" index=\"index\" collection=\"pcbaWorkshopIdList\"\n" +
            "                         open=\"(\" separator=\",\" close=\")\">\n" +
            "                    #{item}\n" +
            "                </foreach>\n" +
            "            </if>\n" +
            "<if test=\"pcbaProcessIdList != null and pcbaProcessIdList.size() > 0 \">\n" +
            "                and pcba_process_id in\n" +
            "                <foreach item=\"item\" index=\"index\" collection=\"pcbaProcessIdList\"\n" +
            "                         open=\"(\" separator=\",\" close=\")\">\n" +
            "                    #{item}\n" +
            "                </foreach>\n" +
            "            </if>\n" +
            "<if test='status != null and status != \"\" '>" +
            " and status = #{status}" +
            "</if>" +
            "<if test='paramsStatusBase != null and paramsStatusBase != \"\" '>" +
            " and params_status_base = #{paramsStatusBase}" +
            "</if>" +
            "<if test=\"companyIdList != null and companyIdList.size() > 0 \">\n" +
            "                and pcba_company_id in\n" +
            "                <foreach item=\"item\" index=\"index\" collection=\"companyIdList\"\n" +
            "                         open=\"(\" separator=\",\" close=\")\">\n" +
            "                    #{item}\n" +
            "                </foreach>\n" +
            "            </if>\n" +
            "<if test='begin != null and pageSize != null and pageSize != \"\" '>" +
            " limit #{begin}, #{pageSize}" +
            "</if>" +
            "</script>")
    Integer getAllPcbaLineViewCount(@Param("pcbaLineNameList") List<String> pcbaLineNameList, @Param("pcbaWorkshopIdList") List<String> pcbaWorkshopIdList, @Param("pcbaProcessIdList") List<String> pcbaProcessIdList, @Param("status") Integer status, @Param("paramsStatusBase") Integer paramsStatusBase, @Param("begin") Integer begin, @Param("pageSize") Integer pageSize, @Param("companyIdList") List<Integer> companyIdList);


    /**
     * 根据复选条件查询
     *
     * @param status
     * @param begin
     * @param pageSize
     * @return
     */
    @Select("<script>" +
            "select * from " + DB1TableName.PCBA_LINE + " where 1 = 1 " +
            "<if test=\"pcbaLineNameList != null and pcbaLineNameList.size() > 0 \">\n" +
            "                and pcba_line_name_cn in\n" +
            "                <foreach item=\"item\" index=\"index\" collection=\"pcbaLineNameList\"\n" +
            "                         open=\"(\" separator=\",\" close=\")\">\n" +
            "                    #{item}\n" +
            "                </foreach>\n" +
            "            </if>\n" +
            "<if test=\"pcbaWorkshopIdList != null and pcbaWorkshopIdList.size() > 0 \">\n" +
            "                and pcba_workshop_id in\n" +
            "                <foreach item=\"item\" index=\"index\" collection=\"pcbaWorkshopIdList\"\n" +
            "                         open=\"(\" separator=\",\" close=\")\">\n" +
            "                    #{item}\n" +
            "                </foreach>\n" +
            "            </if>\n" +
            "<if test=\"pcbaProcessIdList != null and pcbaProcessIdList.size() > 0 \">\n" +
            "                and pcba_process_id in\n" +
            "                <foreach item=\"item\" index=\"index\" collection=\"pcbaProcessIdList\"\n" +
            "                         open=\"(\" separator=\",\" close=\")\">\n" +
            "                    #{item}\n" +
            "                </foreach>\n" +
            "            </if>\n" +
            "<if test='finalStatus != null and finalStatus != \"\" '>" +
            " and final_status = #{finalStatus}" +
            "</if>" +
            "<if test=\"companyIdList != null and companyIdList.size() > 0 \">\n" +
            "                and pcba_company_id in\n" +
            "                <foreach item=\"item\" index=\"index\" collection=\"companyIdList\"\n" +
            "                         open=\"(\" separator=\",\" close=\")\">\n" +
            "                    #{item}\n" +
            "                </foreach>\n" +
            "            </if>\n" +
            " order by pcba_company_id,pcba_workshop_id, SUBSTRING_INDEX(pcba_line_name_cn, ' ', 1),CAST(SUBSTRING_INDEX(pcba_line_name_cn, ' ', -1) AS SIGNED)" +
            "<if test='begin != null and pageSize != null and pageSize != \"\" '>" +
            " limit #{begin}, #{pageSize}" +
            "</if>" +
            "</script>")
    @ResultMap(value = "pcbaLineResultMap")
    List<PcbaLine> getAllPcbaLineViewNew(@Param("pcbaLineNameList") List<String> pcbaLineNameList, @Param("pcbaWorkshopIdList") List<String> pcbaWorkshopIdList, @Param("pcbaProcessIdList") List<String> pcbaProcessIdList, @Param("finalStatus") Integer finalStatus, @Param("begin") Integer begin, @Param("pageSize") Integer pageSize, @Param("companyIdList") List<Integer> companyIdList);

    /**
     * 查询总数
     */
    @Select("<script>" +
            "select count(*) from " + DB1TableName.PCBA_LINE + " where 1 = 1 " +
            "<if test=\"pcbaLineNameList != null and pcbaLineNameList.size() > 0 \">\n" +
            "                and pcba_line_name_cn in\n" +
            "                <foreach item=\"item\" index=\"index\" collection=\"pcbaLineNameList\"\n" +
            "                         open=\"(\" separator=\",\" close=\")\">\n" +
            "                    #{item}\n" +
            "                </foreach>\n" +
            "            </if>\n" +
            "<if test=\"pcbaWorkshopIdList != null and pcbaWorkshopIdList.size() > 0 \">\n" +
            "                and pcba_workshop_id in\n" +
            "                <foreach item=\"item\" index=\"index\" collection=\"pcbaWorkshopIdList\"\n" +
            "                         open=\"(\" separator=\",\" close=\")\">\n" +
            "                    #{item}\n" +
            "                </foreach>\n" +
            "            </if>\n" +
            "<if test=\"pcbaProcessIdList != null and pcbaProcessIdList.size() > 0 \">\n" +
            "                and pcba_process_id in\n" +
            "                <foreach item=\"item\" index=\"index\" collection=\"pcbaProcessIdList\"\n" +
            "                         open=\"(\" separator=\",\" close=\")\">\n" +
            "                    #{item}\n" +
            "                </foreach>\n" +
            "            </if>\n" +
            "<if test='finalStatus != null and finalStatus != \"\" '>" +
            " and final_status = #{finalStatus}" +
            "</if>" +
            "<if test=\"companyIdList != null and companyIdList.size() > 0 \">\n" +
            "                and pcba_company_id in\n" +
            "                <foreach item=\"item\" index=\"index\" collection=\"companyIdList\"\n" +
            "                         open=\"(\" separator=\",\" close=\")\">\n" +
            "                    #{item}\n" +
            "                </foreach>\n" +
            "            </if>\n" +
            "<if test='begin != null and pageSize != null and pageSize != \"\" '>" +
            " limit #{begin}, #{pageSize}" +
            "</if>" +
            "</script>")
    Integer getAllPcbaLineViewCountNew(@Param("pcbaLineNameList") List<String> pcbaLineNameList, @Param("pcbaWorkshopIdList") List<String> pcbaWorkshopIdList, @Param("pcbaProcessIdList") List<String> pcbaProcessIdList, @Param("finalStatus") Integer finalStatus, @Param("begin") Integer begin, @Param("pageSize") Integer pageSize, @Param("companyIdList") List<Integer> companyIdList);

    /**
     * 删除
     *
     * @param pcbaLineId
     * @return
     */
    @Delete("delete from " + DB1TableName.PCBA_LINE + " where pcba_line_id = #{pcbaLineId}")
    Integer deleteById(@Param("pcbaLineId") Integer pcbaLineId);

    /**
     * 插入
     *
     * @param pcbaLine
     * @return
     */
    @Insert("insert into " + DB1TableName.PCBA_LINE + "(pcba_line_name_cn,pcba_line_name_en,pcba_company_id,pcba_workshop_id,create_time,status,sort,pcba_process_id,pcba_line_type,notes,pcba_line_level,is_filled_declare,begin_time_declare,end_time_declare,params_status_declare,params_notes_declare,begin_time_actual,end_time_actual,params_status_actual,params_notes_actual,is_filled_actual,submitter,auditors,params_status_base,lock_declare,final_status,is_first_create) values " +
            "(#{pcbaLine.pcbaLineNameCn},#{pcbaLine.pcbaLineNameEn},#{pcbaLine.pcbaCompanyId},#{pcbaLine.pcbaWorkshopId},#{pcbaLine.createTime},#{pcbaLine.status},#{pcbaLine.sort},#{pcbaLine.pcbaProcessId},#{pcbaLine.pcbaLineType},#{pcbaLine.notes},#{pcbaLine.pcbaLineLevel},#{pcbaLine.isFilledDeclare},#{pcbaLine.beginTimeDeclare},#{pcbaLine.endTimeDeclare},#{pcbaLine.paramsStatusDeclare},#{pcbaLine.paramsNotesDeclare},#{pcbaLine.beginTimeActual},#{pcbaLine.endTimeActual},#{pcbaLine.paramsStatusActual},#{pcbaLine.paramsNotesActual},#{pcbaLine.isFilledActual},#{pcbaLine.submitter},#{pcbaLine.auditors},#{pcbaLine.paramsStatusBase},#{pcbaLine.lockDeclare},#{pcbaLine.finalStatus},#{pcbaLine.isFirstCreate})")
    // 显式设置主键
    @Options(useGeneratedKeys = true, keyProperty = "pcbaLine.pcbaLineId")
    Integer addPcbaLine(@Param("pcbaLine") PcbaLine pcbaLine);

    /**
     * 更新
     *
     * @param pcbaLine
     * @return
     */
    @Update("<script>" +
            "update " + DB1TableName.PCBA_LINE +
            "<set>" +
            "<if test='pcbaLine.pcbaLineNameCn != null and pcbaLine.pcbaLineNameCn != \"\" '>" +
            " pcba_line_name_cn = #{pcbaLine.pcbaLineNameCn}," +
            "</if>" +
            "<if test='pcbaLine.pcbaLineNameEn != null and pcbaLine.pcbaLineNameEn != \"\" '>" +
            " pcba_line_name_en = #{pcbaLine.pcbaLineNameEn}," +
            "</if>" +
            "<if test='pcbaLine.pcbaCompanyId != null and pcbaLine.pcbaCompanyId != \"\" '>" +
            " pcba_company_id = #{pcbaLine.pcbaCompanyId}," +
            "</if>" +
            "<if test='pcbaLine.pcbaWorkshopId != null and pcbaLine.pcbaWorkshopId != \"\" '>" +
            " pcba_workshop_id = #{pcbaLine.pcbaWorkshopId}," +
            "</if>" +
            "<if test='pcbaLine.pcbaProcessId != null and pcbaLine.pcbaProcessId != \"\" '>" +
            " pcba_process_id = #{pcbaLine.pcbaProcessId}," +
            "</if>" +
            "<if test='pcbaLine.pcbaLineType != null and pcbaLine.pcbaLineType != \"\" '>" +
            " pcba_line_type = #{pcbaLine.pcbaLineType}," +
            "</if>" +
            "<if test='pcbaLine.updateTime != null '>" +
            " update_time = #{pcbaLine.updateTime}," +
            "</if>" +
            "<if test='pcbaLine.status != null and pcbaLine.status != \"\" '>" +
            " status = #{pcbaLine.status}," +
            "</if>" +
            "<if test='pcbaLine.sort != null and pcbaLine.sort != \"\" '>" +
            " sort = #{pcbaLine.sort}," +
            "</if>" +
            "<if test='pcbaLine.notes != null and pcbaLine.notes != \"\" '>" +
            " notes = #{pcbaLine.notes}," +
            "</if>" +
            "<if test='pcbaLine.isFilledDeclare != null and pcbaLine.isFilledDeclare != \"\" '>" +
            " is_filled_declare = #{pcbaLine.isFilledDeclare}," +
            "</if>" +
            "<if test='pcbaLine.isFilledActual != null and pcbaLine.isFilledActual != \"\" '>" +
            " is_filled_actual = #{pcbaLine.isFilledActual}," +
            "</if>" +
            "<if test='pcbaLine.beginTimeDeclare != null '>" +
            " begin_time_declare = #{pcbaLine.beginTimeDeclare}," +
            "</if>" +
            "<if test='pcbaLine.endTimeDeclare != null '>" +
            " end_time_declare = #{pcbaLine.endTimeDeclare}," +
            "</if>" +
            "<if test='pcbaLine.paramsStatusDeclare != null and pcbaLine.paramsStatusDeclare != \"\" '>" +
            " params_status_declare = #{pcbaLine.paramsStatusDeclare}," +
            "</if>" +
            "<if test='pcbaLine.paramsNotesDeclare != null '>" +
            " params_notes_declare = #{pcbaLine.paramsNotesDeclare}," +
            "</if>" +
            "<if test='pcbaLine.beginTimeActual != null '>" +
            " begin_time_actual = #{pcbaLine.beginTimeActual}," +
            "</if>" +
            "<if test='pcbaLine.endTimeActual != null '>" +
            " end_time_actual = #{pcbaLine.endTimeActual}," +
            "</if>" +
            "<if test='pcbaLine.paramsStatusActual != null and pcbaLine.paramsStatusActual != \"\" '>" +
            " params_status_actual = #{pcbaLine.paramsStatusActual}," +
            "</if>" +
            "<if test='pcbaLine.paramsNotesActual != null '>" +
            " params_notes_actual = #{pcbaLine.paramsNotesActual}," +
            "</if>" +
            "<if test='pcbaLine.submitter != null and pcbaLine.submitter != \"\" '>" +
            " submitter = #{pcbaLine.submitter}," +
            "</if>" +
            "<if test='pcbaLine.auditors != null and pcbaLine.auditors != \"\" '>" +
            " auditors = #{pcbaLine.auditors}," +
            "</if>" +
            "<if test='pcbaLine.paramsStatusBase != null and pcbaLine.paramsStatusBase != \"\" '>" +
            " params_status_base = #{pcbaLine.paramsStatusBase}," +
            "</if>" +
            "<if test='pcbaLine.lockDeclare != null and pcbaLine.lockDeclare != \"\" '>" +
            " lock_declare = #{pcbaLine.lockDeclare}," +
            "</if>" +
            "<if test='pcbaLine.finalStatus != null and pcbaLine.finalStatus != \"\" '>" +
            " final_status = #{pcbaLine.finalStatus}," +
            "</if>" +
            "<if test='pcbaLine.isFirstCreate != null '>" +
            " is_first_create = #{pcbaLine.isFirstCreate}," +
            "</if>" +
            "</set>" +
            " where pcba_line_id = #{pcbaLine.pcbaLineId}" +
            "</script>")
    Integer updatePcbaLine(@Param("pcbaLine") PcbaLine pcbaLine);

    /**
     * 根据id查询
     *
     * @param pcbaLineId
     * @return
     */
    @ResultMap(value = "pcbaLineResultMap")
    @Select("select * from " + DB1TableName.PCBA_LINE + " where pcba_line_id = #{pcbaLineId}")
    PcbaLine getPcbaLineById(@Param("pcbaLineId") Integer pcbaLineId);

    @ResultMap(value = "pcbaLineResultMap")
    @Select("<script>" +
            "select * from " + DB1TableName.PCBA_LINE + " where 1 = 1" +
            "<if test='pcbaCompanyId != null and pcbaCompanyId != \"\" '>" +
            " and pcba_company_id = #{pcbaCompanyId}" +
            "</if>" +
            "<if test='pcbaWorkshopId != null and pcbaWorkshopId != \"\" '>" +
            " and pcba_workshop_id = #{pcbaWorkshopId}" +
            "</if>" +
            "<if test='pcbaProcessId != null and pcbaProcessId != \"\" '>" +
            " and pcba_process_id = #{pcbaProcessId}" +
            "</if>" +
            "</script>")
    List<PcbaLine> getPcbaLineByCondition(@Param("pcbaCompanyId") Integer pcbaCompanyId, @Param("pcbaWorkshopId") Integer pcbaWorkshopId, @Param("pcbaProcessId") Integer pcbaProcessId);

    /**
     * 判断是否已存在改名字的线体
     *
     * @param pcbaLineNameCn
     * @param pcbaCompanyId
     * @param pcbaWorkshopId
     * @return
     */
    @ResultMap(value = "pcbaLineResultMap")
    @Select("select * from " + DB1TableName.PCBA_LINE + " where pcba_company_id = #{pcbaCompanyId} and pcba_workshop_id = #{pcbaWorkshopId} and pcba_line_name_cn = #{pcbaLineNameCn}")
    PcbaLine judgeLineNameIsExist(@Param("pcbaLineNameCn") String pcbaLineNameCn, @Param("pcbaCompanyId") Integer pcbaCompanyId, @Param("pcbaWorkshopId") Integer pcbaWorkshopId);

    /**
     * 更新线体等级
     *
     * @param pcbaLineLevel
     * @param pcbaLineId
     * @return
     */
    @Update("update " + DB1TableName.PCBA_LINE + " set pcba_line_level = #{pcbaLineLevel}, update_time = #{updateTime} where pcba_line_id = #{pcbaLineId}")
    Integer updateLineLevel(@Param("pcbaLineLevel") Integer pcbaLineLevel, @Param("pcbaLineId") Integer pcbaLineId, @Param("updateTime") Date updateTime);

    @Update("update " + DB1TableName.PCBA_LINE + " set notes = #{notes}, update_time = #{updateTime} where pcba_line_id = #{pcbaLineId}")
    Integer updateLineNotes(@Param("notes") String notes, @Param("pcbaLineId") Integer pcbaLineId, @Param("updateTime") Date updateTime);

    @Update("update " + DB1TableName.PCBA_LINE + " set pcba_line_level_audit = #{pcbaLineLevelAudit} where pcba_line_id = #{pcbaLineId}")
    Integer updateLineLevelAudit(@Param("pcbaLineLevelAudit") Integer pcbaLineLevelAudit, @Param("pcbaLineId") Integer pcbaLineId);

    @Update("update " + DB1TableName.PCBA_LINE + " set notes_audit = #{notesAudit} where pcba_line_id = #{pcbaLineId}")
    Integer updateLineNotesAudit(@Param("notesAudit") String notesAudit, @Param("pcbaLineId") Integer pcbaLineId);

    /**
     * 清空对应的临时值（审核通过）
     */
    @Update("update " + DB1TableName.PCBA_LINE + " set notes_audit = '',pcba_line_level_audit = '' where pcba_line_id = #{pcbaLineId}")
    Integer clearValueAudit(@Param("pcbaLineId") Integer pcbaLineId);

    /**
     * 将 value 还原成 ValueAudit 的值（审核不通过）
     */
    @Update("update " + DB1TableName.PCBA_LINE + " set notes = notes_audit,pcba_line_level = pcba_line_level_audit where pcba_line_id = #{pcbaLineId}")
    Integer returnValueFromValueAudit(@Param("pcbaLineId") Integer pcbaLineId);

    /**
     * 审核工艺宣称能力
     *
     * @param paramsNotesDeclare
     * @param pcbaLineId
     * @param paramsStatusDeclare
     * @param updateTime
     * @return
     */
    @Update("update " + DB1TableName.PCBA_LINE + " set params_notes_declare = #{paramsNotesDeclare},params_status_declare = #{paramsStatusDeclare},update_time = #{updateTime} where pcba_line_id = #{pcbaLineId}")
    Integer auditPcbaLineTechDeclare(@Param("paramsNotesDeclare") String paramsNotesDeclare, @Param("pcbaLineId") Integer pcbaLineId, @Param("paramsStatusDeclare") Integer paramsStatusDeclare, @Param("updateTime") Date updateTime);

    /**
     * 审核工艺实际能力
     *
     * @param paramsNotesActual
     * @param pcbaLineId
     * @param paramsStatusActual
     * @param updateTime
     * @return
     */
    @Update("update " + DB1TableName.PCBA_LINE + " set params_notes_actual = #{paramsNotesActual},params_status_actual = #{paramsStatusActual},update_time = #{updateTime} where pcba_line_id = #{pcbaLineId}")
    Integer auditPcbaLineTechActual(@Param("paramsNotesActual") String paramsNotesActual, @Param("pcbaLineId") Integer pcbaLineId, @Param("paramsStatusActual") Integer paramsStatusActual, @Param("updateTime") Date updateTime);

    @Select("select max(t.total) from (select SUBSTRING_INDEX(pcba_line_name_cn, ' ', -1) as total from " + DB1TableName.PCBA_LINE + " where pcba_company_id = #{pcbaCompanyId} and pcba_workshop_id = #{pcbaWorkshopId} and pcba_process_id = #{pcbaProcessId}) t")
    Integer getMaxNumLine(@Param("pcbaCompanyId") Integer pcbaCompanyId, @Param("pcbaWorkshopId") Integer pcbaWorkshopId, @Param("pcbaProcessId") Integer pcbaProcessId);

    /**
     * 修改线体的基线认证状态
     */
    @Update("update " + DB1TableName.PCBA_LINE + " set params_status_base = #{paramsStatusBase},params_remark_base = #{paramsRemarkBase} where pcba_line_id = #{pcbaLineId}")
    Integer auditPcbaLineParamBase(@Param("pcbaLineId") Integer pcbaLineId, @Param("paramsStatusBase") Integer paramsStatusBase, @Param("paramsRemarkBase") String paramsRemarkBase);

    /**
     * 修改线体的工艺整线实际能力认证状态
     */
    @Update("update " + DB1TableName.PCBA_LINE + " set params_status_actual = #{paramsStatusActual},params_notes_actual = #{paramsNotesActual} where pcba_line_id = #{pcbaLineId}")
    Integer auditPcbaLineParamTechActual(@Param("pcbaLineId") Integer pcbaLineId, @Param("paramsStatusActual") Integer paramsStatusActual, @Param("paramsNotesActual") String paramsNotesActual);

    /**
     * 根据id列表 按照工厂，车间，工序名排序
     */
    @Select("<script>" +
            "select * from " + DB1TableName.PCBA_LINE + " where 1 = 1 " +
            "<if test='type == 1'>" +
            "<if test=\"lineIds != null and lineIds.size() > 0 \">\n" +
            "                and pcba_line_id in\n" +
            "                <foreach item=\"item\" index=\"index\" collection=\"lineIds\"\n" +
            "                         open=\"(\" separator=\",\" close=\")\">\n" +
            "                    #{item}\n" +
            "                </foreach>\n" +
            "            </if>\n" +
            "</if>" +
            "<if test=\"companyIdList != null and companyIdList.size() > 0 \">\n" +
            "                and pcba_company_id in\n" +
            "                <foreach item=\"item\" index=\"index\" collection=\"companyIdList\"\n" +
            "                         open=\"(\" separator=\",\" close=\")\">\n" +
            "                    #{item}\n" +
            "                </foreach>\n" +
            "            </if>\n" +
            " order by pcba_company_id,pcba_workshop_id,SUBSTRING_INDEX(pcba_line_name_cn, ' ', 1),CAST(SUBSTRING_INDEX(pcba_line_name_cn, ' ', -1) AS SIGNED)" +
            "</script>")
    @ResultMap(value = "pcbaLineResultMap")
    List<PcbaLine> getPcbaLineByIds(@Param("lineIds") List<Integer> lineIds, @Param("type") Integer type, @Param("companyIdList") List<Integer> companyIdList);

    /**
     * 更新宣称能力的确认状态
     */
    @Update("update " + DB1TableName.PCBA_LINE + " set lock_declare = #{lockDeclare} where pcba_line_id = #{pcbaLineId}")
    Integer updatePcbaLineLockDeclare(@Param("pcbaLineId") Integer pcbaLineId, @Param("lockDeclare") Integer lockDeclare);

    /**
     * 更新最终状态
     */
    @Update("update " + DB1TableName.PCBA_LINE + " set final_status = #{finalStatus} where pcba_line_id = #{pcbaLineId}")
    Integer updatePcbaLineFinalStatus(@Param("pcbaLineId") Integer pcbaLineId, @Param("finalStatus") Integer finalStatus);

    /**
     * 修改线体的首次创建标识
     */
    @Update("update " + DB1TableName.PCBA_LINE + " set is_first_create = #{isFirstCreate} where pcba_line_id = #{pcbaLineId}")
    Integer updatePcbaLineIsFirstCreate(@Param("pcbaLineId") Integer pcbaLineId, @Param("isFirstCreate") Integer isFirstCreate);
}
